﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using olierFrm.GeneralCache;

namespace olierFrm.DataBase.FrameWork.Plugin
{
    public class Common
    {
        public const string CommonCachePrefix = "Common=";
        private static List<WS_CommonItems> _Common
        {
            get;
            set;
        }
        public static List<WS_CommonItems> FindByCommonNO(string CommonNO)
        {
            Common.load();
            if (Common._Common == null || Common._Common.Count == 0)
            {
                return null;
            }
            var common =
                from c in Common._Common
                where c.sCommonNO == CommonNO
                orderby Convert.ToInt32(c.sComID)
                select c;
            return common.ToList();
        }
        private static void load()
        {
            if (!Cache.KeyExists("Common="))
            {
                FrameWorkEntity _DBContext = new FrameWorkEntity(ConnectionConfig.FrmEntityConnectionStr);
                Common._Common = _DBContext.WS_CommonItems.ToList();
                Cache.Add("Common=", Common._Common);
                return;
            }
            Common._Common = (List<WS_CommonItems>)Cache.Get("Common=");
        }
    }
}
